package com.zmn.plat.services.impl.orderconfig.track.category;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zmn.common.dto.StatusDTO;
import com.zmn.plat.model.entity.orderconfig.track.category.OrderTrackCategory;
import com.zmn.plat.model.entity.orderconfig.track.category.OrderTrackCategoryQuery;
import com.zmn.plat.persistence.interfaces.orderconfig.track.category.OrderTrackCategoryDao;
import com.zmn.plat.services.interfaces.orderconfig.track.category.OrderTrackCategoryService;

/**
 * @author tanbiao
 * @description
 * @modifier
 * @since 2020/11/17 16:12
 **/
@Service
public class OrderTrackCategoryServiceImpl implements OrderTrackCategoryService {
    @Resource
    private OrderTrackCategoryDao orderTrackCategoryDao;

    @Override
    public OrderTrackCategory findByKey(Integer id) {
        return orderTrackCategoryDao.findByKey(id);
    }

    @Override
    public List<OrderTrackCategory> listByKeys(List<Integer> ids) {
        return orderTrackCategoryDao.listByKeys(ids);
    }

    @Override
    public OrderTrackCategory findByName(String name) {
        return orderTrackCategoryDao.findByName(name);
    }

    @Override
    public Integer findMaxSort() {
        return orderTrackCategoryDao.findMaxSort();
    }

    @Override
    public List<OrderTrackCategory> listPageByQuery(OrderTrackCategoryQuery query) {
        int count = countByQuery(query);
        query.setTotalCount(count);
        return orderTrackCategoryDao.listPageByQuery(query);
    }

    @Override
    public List<OrderTrackCategory> listByQuery(OrderTrackCategoryQuery query) {
        return orderTrackCategoryDao.listByQuery(query);
    }

    @Override
    public Integer countByQuery(OrderTrackCategoryQuery query) {
        return orderTrackCategoryDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(OrderTrackCategory orderTrackCategory) {
        orderTrackCategory.setUpdateTime(new Date());
        return orderTrackCategoryDao.updateByKey(orderTrackCategory);
    }

    @Override
    public Integer updateSortKey(Integer categId, Integer sort, String staffName) {
        OrderTrackCategory cancelCategory = new OrderTrackCategory();
        cancelCategory.setCategId(categId);
        cancelCategory.setSort(sort);
        cancelCategory.setUpdateTime(new Date());
        cancelCategory.setUpdater(staffName);
        cancelCategory.setUpdateTime(new Date());
        return orderTrackCategoryDao.updateSortKey(cancelCategory);
    }

    @Override
    public Integer updateFirstLetterByKey(Integer categId, String firstLetter, String staffName) {
        OrderTrackCategory cancelCategory = new OrderTrackCategory();
        cancelCategory.setCategId(categId);
        cancelCategory.setFirstLetter(firstLetter);
        cancelCategory.setUpdateTime(new Date());
        cancelCategory.setUpdater(staffName);
        return orderTrackCategoryDao.updateFirstLetterByKey(cancelCategory);
    }

    @Override
    public Integer updateStatusBatch(List<Integer> categoryIds, Integer status, String staffName) {
        StatusDTO dto = new StatusDTO();
        dto.setIds(categoryIds);
        dto.setStatus(status);
        dto.setUpdater(staffName);
        dto.setUpdateTime(new Date());
        return orderTrackCategoryDao.updateStatusBatch(dto);
    }

    @Override
    public Integer insert(OrderTrackCategory orderTrackCategory) {
        return orderTrackCategoryDao.insert(orderTrackCategory);
    }

    @Override
    public Integer deleteByKey(Integer id) {
        return orderTrackCategoryDao.deleteByKey(id);
    }
}
